home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / EDO Hack / source code / sources / HackEvents.c < prev    next >
Encoding:
Text File  |  1997-06-28  |  5.3 KB  |  221 lines  |  [TEXT/CWIE]

  1. // --------------------------------------------------------------------------------------
  2. //  HackEvents.c
  3. //
  4. //  Written by Don Arbow and Marc A. Raiser, EveryDay Objects, Inc.
  5. //     in one day - June 26, 1997
  6. // --------------------------------------------------------------------------------------
  7.  
  8. //#include "Subwoofer.h"
  9.  
  10. #include "HackEvents.h"
  11. #include "HackWindows.h"
  12.  
  13. extern Boolean done;
  14.  
  15. static void DoCloseWindow(EventRecord *evt, WindowPtr theWindow);
  16. static void DoClickInContent(EventRecord *evt, WindowPtr theWindow);
  17. static void DoDragWindow(EventRecord *evt, WindowPtr theWindow);
  18. static void DoGrowWindow(EventRecord *evt, WindowPtr theWindow);
  19. static void DoZoom(EventRecord *evt, WindowPtr theWindow, short dir);
  20. static void DoMenu(long msel);
  21. static void DoKey(EventRecord *evt);
  22. static void DrawClippedGrowIcon(WindowPtr theWindow);
  23. static void DoUpdate(EventRecord *evt);
  24. static void ActivateWindow(WindowRef    newFrontWindow);
  25. static void DeactivateWindow(WindowRef    newBehindWindow);
  26. static void DoActivate(EventRecord *evt);
  27. static void DoMFinder(EventRecord *evt);
  28. static void DoClick(EventRecord *evt);
  29.  
  30. //MW Added extern prototypes
  31. extern void MenuDispatch(short menuNumber,short itemNumber);
  32. extern void DrawImage(GrafPtr graf);
  33.  
  34. static void DoCloseWindow(EventRecord *evt, WindowPtr theWindow)
  35. {
  36.     if (TrackGoAway(theWindow,evt->where)) {
  37.         CloseWindow(theWindow);
  38.     }
  39. }
  40.  
  41. static void DoClickInContent(EventRecord *evt, WindowPtr theWindow)
  42. {
  43.     int                part;
  44.     ControlHandle    ctlh;
  45.     Point            pt;
  46.     GrafPtr            saveport;
  47.     Rect            frame;
  48.     
  49.     if (theWindow!=FrontWindow()) {
  50.         SelectWindow(theWindow);
  51.     } else {
  52.         GetPort(&saveport);
  53.         SetPort(theWindow);
  54.         pt = evt->where;
  55.         GlobalToLocal(&pt);
  56.         if (part = FindControl(pt,theWindow,&ctlh)) {
  57.             /* TrackControl Goes Here */
  58.         }
  59.         SetPort(saveport);
  60.     }
  61. }
  62.  
  63. static void DoDragWindow(EventRecord *evt, WindowPtr theWindow)
  64. {
  65. //MW changed screenBits.bounds to qd.screenBits.bounds
  66.     DragWindow(theWindow,evt->where,&qd.screenBits.bounds);
  67. }
  68.  
  69. static void DoGrowWindow(EventRecord *evt, WindowPtr theWindow)
  70. {
  71.     GrowHackWindow(evt, theWindow);
  72. }
  73.  
  74. //MW added void return-types
  75. static void DoZoom(EventRecord *evt, WindowPtr theWindow, short dir)
  76. {
  77.     if (TrackBox(theWindow, evt->where, dir)) {
  78.         ZoomHackWindow(theWindow, dir);
  79.     }
  80. }
  81.  
  82. static void DoMenu(long msel)
  83. {
  84.     int item,menu;
  85.     item = LoWord(msel);
  86.     menu = HiWord(msel);
  87.     MenuDispatch(menu, item);
  88.     HiliteMenu(0);                        /* remove menu title hiliting */
  89. }
  90.  
  91. static void DoKey(EventRecord *evt)
  92. {
  93.     char        c;
  94.     
  95.     c = (char)evt->message & charCodeMask;
  96.     
  97.     if ((evt->modifiers & cmdKey) == false) {
  98. //        KeyPressed = true;
  99. //        KeyValue = c;
  100.     } else {
  101.         DoMenu(MenuKey(evt->message & charCodeMask));    
  102.     }
  103. }
  104.  
  105. static void DrawClippedGrowIcon(WindowPtr theWindow)
  106. /*
  107.     Clip out the lines that appear
  108.     on the sides of a window with a grow icon.
  109. */
  110. {
  111.     Rect        clip;
  112.     RgnHandle    oldClip;
  113.     
  114.     oldClip = NewRgn();
  115.     GetClip(oldClip);
  116.     clip = theWindow->portRect;
  117.     clip.left = clip.right - 15;
  118.     clip.top = clip.bottom - 15;
  119.  
  120.     ClipRect(&clip);
  121.     
  122.     DrawGrowIcon(theWindow);
  123.     SetClip(oldClip);
  124. }
  125.  
  126. static void DoUpdate(EventRecord *evt)
  127. {
  128.     WindowPtr    updateWindow;
  129.     GrafPtr        savePort;
  130.     
  131.     GetPort(&savePort);                        /* save current port */
  132.     
  133.     updateWindow = (WindowPtr)evt->message;    /* get windowPtr from event msg */
  134.  
  135.     UpdateHackWindow(updateWindow);
  136. }
  137.  
  138.  
  139. static void ActivateWindow(WindowRef    newFrontWindow)
  140. {
  141.     ActivateHackWindow(newFrontWindow);
  142. }
  143.  
  144. static void DeactivateWindow(WindowRef    newBehindWindow)
  145. {
  146.     DeactivateHackWindow(newBehindWindow);
  147. }
  148.  
  149. static void DoActivate(EventRecord *evt)
  150. {
  151.     if (evt->modifiers & activeFlag)
  152.         ActivateWindow((WindowRef)evt->message);
  153.     else
  154.         DeactivateWindow((WindowRef)evt->message);
  155. }
  156.  
  157. static void DoMFinder(EventRecord *evt)
  158. {
  159. //    if ((evt->message >> 24) == suspendResumeMessage)
  160. //        BackgroundFlag = !(evt->message & resumeFlag);
  161. }
  162.  
  163. static void DoClick(EventRecord *evt)
  164. {
  165.     WindowPtr    theWindow;
  166.     
  167.     switch (FindWindow(evt->where, &theWindow)) {
  168.         case inDesk:        break;
  169.         case inMenuBar:        DoMenu(MenuSelect(evt->where));
  170.                             break;
  171.         case inSysWindow:    SystemClick(evt,theWindow);
  172.                             break;
  173.         case inContent:        ClickHackWindow(evt,theWindow);
  174.                             break;
  175.         case inDrag:        DoDragWindow(evt,theWindow);
  176.                             break;
  177.         case inGrow:        DoGrowWindow(evt,theWindow);
  178.                             break;
  179.         case inGoAway:        DoCloseWindow(evt,theWindow);
  180.                             break;
  181.         case inZoomIn:        DoZoom(evt,theWindow,inZoomIn);
  182.                             break;
  183.         case inZoomOut:        DoZoom(evt,theWindow,inZoomOut);
  184.                             break;
  185.         default:            break;
  186.     }
  187. }
  188.  
  189. void EventLoop(void) {
  190.  
  191.     static EventRecord    event;
  192.     Boolean        eventOccured;
  193.     
  194. //    KeyPressed = false;                /* set to false every time through    */
  195.     
  196.     eventOccured = WaitNextEvent(everyEvent,&event,10,nil);
  197.  
  198.     if (eventOccured) {
  199.         switch (event.what) {
  200.             case nullEvent:                                        break;
  201.             case mouseDown:            DoClick(&event);            break;
  202.             case mouseUp:                                         break;
  203.             case keyDown:            DoKey(&event);                break;
  204.             case keyUp:                                             break;
  205.             case autoKey:            DoKey(&event);                break;
  206.             case updateEvt:            DoUpdate(&event);            break;
  207.             case diskEvt:                                         break;
  208.             case activateEvt:        DoActivate(&event);            break;
  209.             //case networkEvt:                                    break;
  210.             //case driverEvt:                                     break;
  211.             //case app1Evt:                                         break;
  212.             //case app2Evt:                                         break;
  213.             //case app3Evt:                                         break;
  214.             case osEvt:                DoMFinder(&event);            break;
  215.             default:                                            break;
  216.         }
  217.     }
  218. }
  219.  
  220.  
  221.